#pragma once
#include"noncopyable.h"

#include<functional>
#include<string>
#include<vector>
#include<memory>
class Eventloop;
class EventloopThread;

class EventloopThreadPool:noncopyable
{
    public:
        using ThreadInitCallback=std::function<void(Eventloop*)>;
        EventloopThreadPool(Eventloop *baseloop,const std::string &nameArg);
        ~EventloopThreadPool();
        void setThreadNum(int numThreads){numThreads_=numThreads;}//设置底层线程数量
        void start(const ThreadInitCallback &cb=ThreadInitCallback());//相当于开始启动设置的数量的线程
        
        //如果工作在多线程中，baseloop_默认以轮循的方式分配channel给subloop
        Eventloop* getNextloop();
        std::vector<Eventloop*> getAllLoops();
        bool started() const {return started_;}
        const std::string name() const {return name_;}
    private:
        Eventloop *baseloop_;//起码至少有一个用户线程
        std::string name_;
        bool started_;
        int numThreads_;
        int next_;//轮循的下标
        std::vector<std::unique_ptr<EventloopThread>>threads_;
        std::vector<Eventloop*>loops_;
};
